package tests.jdl.databaseObjects.sqlite.datatypes;

import jdl.databaseObjects.DbType;
import jdl.databaseObjects.DbTypeUnknownException;
import jdl.databaseObjects.sqlite.datatypes.VarcharDbType;
import junit.framework.Assert;

import org.junit.Test;

public class VarcharDbType_Test {
	@Test
	public void getTypeAsString_SizeGreaterZero() {
		VarcharDbType type = new VarcharDbType(50);
		Assert.assertEquals("varchar(50)", type.getTypeAsString());
	}

	@Test
	public void fromString_SizeIs10() throws DbTypeUnknownException {
		DbType type = VarcharDbType.fromString("vArChAr (10)");
		Assert.assertEquals(10, type.getSize());
		Assert.assertEquals(VarcharDbType.class, type.getClass());
	}

	@Test
	public void fromString_SizeIs50() throws DbTypeUnknownException {
		DbType type = VarcharDbType.fromString("vArChAr (50)");
		Assert.assertEquals(50, type.getSize());
		Assert.assertEquals(VarcharDbType.class, type.getClass());
	}

	@Test(expected = DbTypeUnknownException.class)
	public void fromString_typeAsStringIs_r() throws DbTypeUnknownException {
		VarcharDbType.fromString("r");
	}

	@Test(expected = DbTypeUnknownException.class)
	public void fromString_typeAsStringIs_r_leftBracket_4_leftBracket()
			throws DbTypeUnknownException {
		VarcharDbType.fromString("r(4(");
	}

	@Test
	public void getSize_sizeIs30() {
		VarcharDbType type = new VarcharDbType(30);
		Assert.assertEquals(30, type.getSize());
	}
}
